package com.example.spider.config.support;

import com.example.spider.config.support.method.MethodArgumentResolver;
import com.example.spider.proxy.core.ProxyInfo;
import com.example.spider.task.Task;
import org.springframework.core.MethodParameter;
import org.springframework.web.method.support.ModelAndViewContainer;

public class SpiderProxyInfoArgumentResolver implements MethodArgumentResolver {

    @Override
    public boolean supportsParameter(MethodParameter parameter) {
        Class<?> paramType = parameter.getParameterType();
        return (ProxyInfo.class.isAssignableFrom(paramType));
    }

    /**
     * Set {@link ModelAndViewContainer#setRequestHandled(boolean)} to
     * {@code false} to indicate that the method signature provides access
     * to the response. If subsequently the underlying method returns
     * {@code null}, the request is considered directly handled.
     */
    @Override
    public Object resolveArgument(MethodParameter parameter, Object... params) throws Exception {
        return ((Task<?>) params[0]).getActuallyProxy();
    }


}
